package com.wbdgj.ui.booking;

import android.content.Context;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import com.wbdgj.R;
import com.wbdgj.base.BaseActivity;
import com.wbdgj.ui.mine.Coupon01Fragment;
import com.wbdgj.ui.mine.Coupon02Fragment;
import com.wbdgj.ui.mine.Coupon03Fragment;
import com.wbdgj.ui.mine.YhjActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class OrderActivity extends BaseActivity {
    private Context context = this;

    private static TabLayout mTabLayout;
    @BindView(R.id.destination_viewpager)
    ViewPager mViewPager;

    private MyFragmentPagerAdapter adapter;
    private List<Fragment> fragments;
    private Order01Fragment order01Fragment;
    private Order02Fragment order02Fragment;
    private Order03Fragment order03Fragment;
    private Order04Fragment order04Fragment;
    private Order05Fragment order05Fragment;

    private int item;
    private String ID_CARD;

    @Override
    protected int getLayoutResId() {
        return R.layout.ui_order;
    }

    @Override
    protected void initView() {
        item = getIntent().getIntExtra("item", 0);
        ID_CARD = getIntent().getStringExtra("ID_CARD");
        mTabLayout = (TabLayout) findViewById(R.id.destination_tab_layout);
        Bundle bundle = new Bundle();
        bundle.putString("ID_CARD", ID_CARD);
        fragments = new ArrayList<>();
        fragments.add(order01Fragment = (Order01Fragment) Fragment.instantiate(context,Order01Fragment.class.getName()));
        fragments.add(order02Fragment = (Order02Fragment)Fragment.instantiate(context,Order02Fragment.class.getName()));
        fragments.add(order03Fragment = (Order03Fragment)Fragment.instantiate(context,Order03Fragment.class.getName()));
        fragments.add(order04Fragment = (Order04Fragment)Fragment.instantiate(context,Order04Fragment.class.getName()));
        fragments.add(order05Fragment = (Order05Fragment)Fragment.instantiate(context,Order05Fragment.class.getName()));
        adapter = new MyFragmentPagerAdapter(getSupportFragmentManager());

        order01Fragment.setArguments(bundle);
        order02Fragment.setArguments(bundle);
        order03Fragment.setArguments(bundle);
        order04Fragment.setArguments(bundle);
        order05Fragment.setArguments(bundle);

        mViewPager.setAdapter(adapter);
        mViewPager.setCurrentItem(item);
        mTabLayout.setupWithViewPager(mViewPager);
        mTabLayout.getTabAt(0).setText("全部");
        mTabLayout.getTabAt(1).setText("已取消");
        mTabLayout.getTabAt(2).setText("待支付");
        mTabLayout.getTabAt(3).setText("待处理");
        mTabLayout.getTabAt(4).setText("已完成");

    }

    private class MyFragmentPagerAdapter extends FragmentPagerAdapter {
        public MyFragmentPagerAdapter(FragmentManager fm) {
            super(fm);

        }
        @Override
        public Fragment getItem(int position) {
            return fragments.get(position);
        }

        @Override
        public int getCount() {
            return fragments.size();
        }
    }

}